'use client' import React from 'react' import { Box, Button } from '@mui/material' import { pi } from '@/webWorker/worker' interface PiWebWorkerProps { piIterations: number } export default function PiWebWorker(props: PiWebWorkerProps) { const workerRef = React.useRef(null) React.useEffect(() => { workerRef.current = new Worker(new URL('../../../webWorker/worker.ts', import.meta.url)) workerRef.current.onmessage = (event: MessageEvent) => alert(`WebWorker Response => ${event.data}`) return () => { workerRef.current?.terminate() } }, []) const processPiWebWorker = React.useCallback(() => { workerRef.current?.postMessage(props.piIterations) }, [props.piIterations]) const processPiMainThread = () => { alert(pi(props.piIterations)) } return ( ) }